<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>props 初体验</title>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <!-- 1. 引入 prop 文件 -->
    <script src="../js/prop-types.js"></script>

    <script type="text/babel">
        //外部数据
        let obj = {
            age: 19,
            gender: '男'
        }

        class App extends React.Component{
            // 2. 在类的内部 声明一个『静态』的属性
            static propTypes = {
                name: PropTypes.string.isRequired,   //isRequired 必填
                age: PropTypes.number,
                gender: PropTypes.string
            }

            //3. 默认值设置  default 默认  props 属性
            static defaultProps = {
                name: '张三'
            }

            render(){
                let {name, age, gender} = this.props;
                return <div>
                        <ul>
                            <li>姓名: {name}</li>
                            <li>年龄: {age}</li>
                            <li>性别: {gender}</li>
                        </ul>
                        <hr />
                    </div>
            }
        }

        ReactDOM.render(<App  name={obj.name} age={obj.age} gender={obj.gender}    />, document.querySelector("#root"));

    </script>
</body>
</html>